import * as types from "./mutation-types";
import Api from "api/api";
const state = {
  departCategories: [],
  currentDepartCategory: {}
};

const getters = {
  departCategories: state => state.departCategories,
  currentDepartCategory: state => state.currentDepartCategory
};

const actions = {
  getDepartCategories({ commit }, param) {
    return Api.getDepartCategories(param).then(ret => {
      commit(types.UPDATE_DEPART_CATEGORY_LIST, ret.data.data);
      return ret;
    });
  },
  addDepartCategories({ commit }, payload) {
    return Api.addCategories({ body: payload }).then(ret => {
      return ret;
    });
  },

  deleteDepartCategories({ commit }, param) {
    return Api.deleteCategories(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.INIT_CURRENT_DEPART_CATEGORY](state) {
    state.currentDepartCategory = {
      clazz: ""
    };
  },
  [types.UPDATE_DEPART_CATEGORY_LIST](state, payload) {
    state.departCategories = payload;
  },
  [types.UPDATE_CURRENT_DEPART_CATEGORY](state, payload) {
    state.currentDepartCategory = payload;
  }
};
export default {
  state,
  getters,
  actions,
  mutations
};
